package net.plankton.rules;

import java.rmi.RemoteException;
import java.util.Iterator;

import javax.rules.ConfigurationException;
import javax.rules.RuleRuntime;
import javax.rules.RuleServiceProvider;
import javax.rules.RuleServiceProviderManager;
import javax.rules.StatefulRuleSession;

public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Test t = new Test();
		t.useSession();
	}

	
	public void useSession() {
		
		try {
			String ruleServiceProviderClassName = biz.hammurapi.rules.jsr94.FileRuleServiceProvider.class.getName();
			RuleServiceProvider serviceProvider = RuleServiceProviderManager.getRuleServiceProvider(ruleServiceProviderClassName);
			RuleRuntime runtime = serviceProvider.getRuleRuntime();
			StatefulRuleSession session = (StatefulRuleSession)runtime.createRuleSession("/home/hacklm/workspace/ruleset.xml", null, RuleRuntime.STATEFUL_SESSION_TYPE);
		
			session.executeRules();
			for (Iterator it = session.getObjects().iterator();it.hasNext();) {
				System.err.println(it.next());
			}
			
			
			session.release();
			
		} catch (ConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (Exception ex) {
			ex.printStackTrace();
		}
		
	}
	
}
